<?php
/**
 * 登录/退出登录
 * @author Administrator
 *
 */
class login extends CController{
	
	public function show()
	{
		if(isset($_POST["username"]))
		{
			$userName = $this->getRequestData("username");
			$pwd = $this->getRequestData("password");
			$pwd = CCommon::pwdMd5($pwd);
			$userModel = new baseUserModel();
			$userInfo = $userModel->userLogin($userName,$pwd);
			
			if(!$userInfo)
			{
				$this->setViewParam("jsBlock", "<script>alert('用户名或密码错误');</script>");
			}
			else{
				$_SESSION["manageInfo"] = $userInfo;

				$pageRightList = $userModel->selectUserPageRight($userInfo["user_id"]);

				$_SESSION["manageInfo"]["pageRight"] = $pageRightList;
				
				//var_dump($pageRightList);
				//echo "<br /><br />";
				//var_dump($_SESSION["manageInfo"]["pageRight"]);exit;
				
				$userModel->afterLogin($userInfo["user_id"]);
				header("location:".Config::get("manageDomain")."index/show");
				exit;
			}
		}
		$this->setViewParam("imgDomain",Config::get("imgDomain"));
		$this->render("admin/login",array(),false);
	}
	
	public function logout()
	{
		unset($_SESSION["manageInfo"]);
		header("location:".Config::get("manageDomain")."login/show");
		exit();
	}
}